home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / ds3100.md / bfd / doc / bfd.info-2 < prev    next >
Encoding:
Text File  |  1992-07-01  |  47.2 KB  |  1,606 lines

  1. Info file bfd.info, produced by Makeinfo, -*- Text -*- from input
  2. file ./bfd.texinfo.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * Bfd: (bfd).            The Binary File Descriptor library.
  6. END-INFO-DIR-ENTRY
  7.  
  8. This file documents the BFD library.
  9.  
  10. Copyright (C) 1991 Free Software Foundation, Inc.
  11.  
  12. Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16. Permission is granted to copy and distribute modified versions of this
  17. manual under the conditions for verbatim copying, subject to the
  18. terms of the GNU General Public License, which includes the provision
  19. that the entire resulting derived work is distributed under the terms
  20. of a permission notice identical to this one.
  21.  
  22. Permission is granted to copy and distribute translations of this
  23. manual into another language, under the above conditions for modified
  24. versions.
  25.  
  26.  
  27. 
  28. File: bfd.info,  Node: Formats,  Next: Relocations,  Prev: Archives,  Up: BFD front end
  29.  
  30. File Formats
  31. ============
  32.  
  33. A format is a BFD concept of high level file contents. The formats
  34. supported by BFD are:
  35.  
  36. *  The BFD may contain data, symbols, relocations and debug info.
  37.  
  38. * The BFD contains other BFDs and an optional index.
  39.  
  40. * The BFD contains the result of an executable core dump.
  41.  
  42.  
  43. `bfd_check_format'
  44. ...................
  45.  
  46. *Synopsis*
  47.  
  48. boolean bfd_check_format(bfd *abfd, bfd_format format);
  49.  
  50. *Description*
  51.  This routine is supplied a BFD and a format. It attempts to verify if the
  52. file attached to the BFD is indeed compatible with the format
  53. specified (ie, one of `bfd_object', `bfd_archive' or `bfd_core').  If
  54. the BFD has been set to a specific TARGET before the call, only the
  55. named target and format combination will be checked. If the target
  56. has not been set, or has been set to `default' then all the known
  57. target backends will be interrogated to determine a match.  The
  58. function returns `true' on success, otherwise `false' with one of the
  59. following error codes:
  60.  
  61. * if `format' is not one of `bfd_object', `bfd_archive'or `bfd_core'.
  62.  
  63. * if an error occured during a read -  even some file mismatches can
  64. cause system_call_errros
  65.  
  66. * none of the backends recognised the file format
  67.  
  68. * more than one backend recognised the file format.
  69.  
  70.  
  71. `bfd_set_format'
  72. .................
  73.  
  74. *Synopsis*
  75.  
  76. boolean bfd_set_format(bfd *, bfd_format);
  77.  
  78. *Description*
  79.  This function sets the file format of the supplied BFD to the format
  80. requested. If the target set in the BFD does not support the format
  81. requested, the format is illegal or the BFD is not open for writing
  82. than an error occurs.
  83.  
  84. `bfd_format_string'
  85. ...................
  86.  
  87. *Synopsis*
  88.  
  89. CONST char *bfd_format_string(bfd_format);
  90.  
  91. *Description*
  92.  This function takes one argument, and enumerated type (bfd_format) and
  93. returns a pointer to a const string `invalid', `object', `archive',
  94. `core' or `unknown' depending upon the value of the enumeration.
  95.  
  96.  
  97. 
  98. File: bfd.info,  Node: Relocations,  Next: Core Files,  Prev: Formats,  Up: BFD front end
  99.  
  100. Relocations
  101. ===========
  102.  
  103. BFD maintains relocations in much the same was as it maintains symbols;
  104. they are left alone until required, then read in en-mass and
  105. traslated into an internal form. There is a common routine
  106. `bfd_perform_relocation' which acts upon the canonical form to to the
  107. actual fixup.  Note that relocations are maintained on a per section
  108. basis, whilst symbols are maintained on a per BFD basis.  All a back
  109. end has to do to fit the BFD interface is to create as many `struct
  110. reloc_cache_entry' as there are relocations in a particuar section,
  111. and fill in the right bits:
  112.  
  113. * Menu:
  114.  
  115. * typedef arelent::
  116. * howto manager::
  117.  
  118.  
  119.  
  120. 
  121. File: bfd.info,  Node: typedef arelent,  Next: howto manager,  Prev: Relocations,  Up: Relocations
  122.  
  123. typedef arelent
  124. ---------------
  125.  
  126. This is the structure of a relocation entry:
  127.  
  128. .
  129.  
  130. typedef enum bfd_reloc_status 
  131. {
  132.            /* No errors detected */
  133.   bfd_reloc_ok,
  134.  
  135.            /* The relocation was performed, but there was an overflow. */
  136.   bfd_reloc_overflow,
  137.  
  138.            /* The address to relocate was not within the section supplied*/
  139.   bfd_reloc_outofrange,
  140.  
  141.            /* Used by special functions */
  142.   bfd_reloc_continue,
  143.  
  144.            /* Unused */
  145.   bfd_reloc_notsupported,
  146.  
  147.            /* Unsupported relocation size requested.  */
  148.   bfd_reloc_other,
  149.  
  150.            /* The symbol to relocate against was undefined.*/
  151.   bfd_reloc_undefined,
  152.  
  153.            /* The relocation was performed, but may not be ok - presently
  154.           generated only when linking i960 coff files with i960 b.out
  155.           symbols. */
  156.   bfd_reloc_dangerous
  157.  }
  158.  bfd_reloc_status_type;
  159.  
  160.  
  161. typedef struct reloc_cache_entry 
  162. {
  163.            /* A pointer into the canonical table of pointers  */
  164.   struct symbol_cache_entry **sym_ptr_ptr;
  165.  
  166.            /* offset in section */
  167.   rawdata_offset address;
  168.  
  169.            /* addend for relocation value */
  170.   bfd_vma addend;    
  171.  
  172.            /* Pointer to how to perform the required relocation */
  173.   CONST struct reloc_howto_struct *howto;
  174.  
  175. } arelent;
  176.  
  177. *Description*
  178.  Here is a description of each of the fields within a relent:
  179.  
  180. *  The symbol table pointer points to a pointer to the symbol
  181. associated with the relocation request. This would naturally be the
  182. pointer into the table returned by the back end's get_symtab action.
  183. *Note Symbols::. The symbol is referenced through a pointer to a
  184. pointer so that tools like the linker can fix up all the symbols of
  185. the same name by modifying only one pointer. The relocation routine
  186. looks in the symbol and uses the base of the section the symbol is
  187. attached to and the value of the symbol as the initial relocation
  188. offset. If the symbol pointer is zero, then the section provided is
  189. looked up.
  190.  
  191. * The address field gives the offset in bytes from the base of the
  192. section data which owns the relocation record to the first byte of
  193. relocatable information. The actual data relocated will be relative
  194. to this point - for example, a relocation type which modifies the
  195. bottom two bytes of a four byte word would not touch the first byte
  196. pointed to in a big endian world.
  197.  
  198. * end to be added (!) to the relocation offset. Its interpretation is
  199. dependent upon the howto. For example, on the 68k the code:
  200.  
  201.              char foo[];
  202.              main()
  203.                      {
  204.                      return foo[0x12345678];
  205.                      }
  206.  
  207. Could be compiled into:
  208.  
  209.              linkw fp,#-4
  210.              moveb @#12345678,d0
  211.              extbl d0
  212.              unlk fp
  213.              rts
  214.  
  215. This could create a reloc pointing to foo, but leave the offset in
  216. the data (something like)
  217.  
  218.      RELOCATION RECORDS FOR [.text]:
  219.      offset   type      value 
  220.      00000006 32        _foo
  221.      
  222.      00000000 4e56 fffc          ; linkw fp,#-4
  223.      00000004 1039 1234 5678     ; moveb @#12345678,d0
  224.      0000000a 49c0               ; extbl d0
  225.      0000000c 4e5e               ; unlk fp
  226.      0000000e 4e75               ; rts
  227.  
  228. Using coff and an 88k, some instructions don't have enough space in
  229. them to represent the full address range, and pointers have to be
  230. loaded in two parts. So you'd get something like:
  231.  
  232.              or.u     r13,r0,hi16(_foo+0x12345678)
  233.              ld.b     r2,r13,lo16(_foo+0x12345678)
  234.              jmp      r1
  235.  
  236. This whould create two relocs, both pointing to _foo, and with
  237. 0x12340000 in their addend field. The data would consist of:
  238.  
  239.      RELOCATION RECORDS FOR [.text]:
  240.      offset   type      value 
  241.      00000002 HVRT16    _foo+0x12340000
  242.      00000006 LVRT16    _foo+0x12340000
  243.  
  244.      00000000 5da05678           ; or.u r13,r0,0x5678
  245.      00000004 1c4d5678           ; ld.b r2,r13,0x5678
  246.      00000008 f400c001           ; jmp r1
  247.  
  248. The relocation routine digs out the value from the data, adds it to
  249. the addend to get the original offset and then adds the value of
  250. _foo. Note that all 32 bits have to be kept around somewhere, to cope
  251. with carry from bit 15 to bit 16.  On further example is the sparc
  252. and the a.out format. The sparc has a similar problem to the 88k, in
  253. that some instructions don't have room for an entire offset, but on
  254. the sparc the parts are created odd sized lumps. The designers of the
  255. a.out format chose not to use the data within the section for storing
  256. part of the offset; all the offset is kept within the reloc. Any
  257. thing in the data should be ignored.
  258.  
  259.              save %sp,-112,%sp
  260.              sethi %hi(_foo+0x12345678),%g2
  261.              ldsb [%g2+%lo(_foo+0x12345678)],%i0
  262.              ret
  263.              restore
  264.  
  265. Both relocs contains a pointer to foo, and the offsets would contain
  266. junk.
  267.  
  268.      RELOCATION RECORDS FOR [.text]:
  269.      offset   type      value 
  270.      00000004 HI22      _foo+0x12345678
  271.      00000008 LO10      _foo+0x12345678
  272.  
  273.      00000000 9de3bf90     ; save %sp,-112,%sp
  274.      00000004 05000000     ; sethi %hi(_foo+0),%g2
  275.      00000008 f048a000     ; ldsb [%g2+%lo(_foo+0)],%i0
  276.      0000000c 81c7e008     ; ret
  277.      00000010 81e80000     ; restore
  278.  
  279. *  The howto field can be imagined as a relocation instruction. It is a
  280. pointer to a struct which contains information on what to do with all
  281. the other information in the reloc record and data section. A back
  282. end would normally have a relocation instruction set and turn
  283. relocations into pointers to the correct structure on input - but it
  284. would be possible to create each howto field on demand.
  285.  
  286.  
  287. `reloc_howto_type'
  288. ...................
  289.  
  290. The `reloc_howto_type' is a structure which contains all the
  291. information that BFD needs to know to tie up a back end's data.
  292.  
  293. .struct symbol_cache_entry;            /* Forward declaration */
  294.  
  295.  
  296. typedef CONST struct reloc_howto_struct 
  297.            /*  The type field has mainly a documetary use - the back end can
  298.            to what it wants with it, though the normally the back end's
  299.            external idea of what a reloc number would be would be stored
  300.            in this field. For example, the a PC relative word relocation
  301.            in a coff environment would have the type 023 - because that's
  302.            what the outside world calls a R_PCRWORD reloc. */
  303.   unsigned int type;
  304.  
  305.            /*  The value the final relocation is shifted right by. This drops
  306.            unwanted data from the relocation.  */
  307.   unsigned int rightshift;
  308.  
  309.            /*  The size of the item to be relocated - 0, is one byte, 1 is 2
  310.            bytes, 3 is four bytes. */
  311.   unsigned int size;
  312.  
  313.            /*  Now obsolete */
  314.   unsigned int bitsize;
  315.  
  316.            /*  Notes that the relocation is relative to the location in the
  317.            data section of the addend. The relocation function will
  318.            subtract from the relocation value the address of the location
  319.            being relocated. */
  320.   boolean pc_relative;
  321.  
  322.            /*  Now obsolete */
  323.   unsigned int bitpos;
  324.  
  325.            /*  Now obsolete */
  326.   boolean absolute;
  327.  
  328.            /* Causes the relocation routine to return an error if overflow
  329.           is detected when relocating. */
  330.   boolean complain_on_overflow;
  331.  
  332.            /* If this field is non null, then the supplied function is
  333.           called rather than the normal function. This allows really
  334.           strange relocation methods to be accomodated (eg, i960 callj
  335.           instructions). */
  336.   bfd_reloc_status_type EXFUN ((*special_function), 
  337.                         (bfd *abfd,
  338.                          arelent *reloc_entry,
  339.                                             struct symbol_cache_entry *symbol,
  340.                                             PTR data,
  341.                                             asection *input_section));
  342.  
  343.            /* The textual name of the relocation type. */
  344.   char *name;
  345.  
  346.            /* When performing a partial link, some formats must modify the
  347.           relocations rather than the data - this flag signals this.*/
  348.   boolean partial_inplace;
  349.  
  350.            /* The src_mask is used to select what parts of the read in data
  351.           are to be used in the relocation sum. Eg, if this was an 8 bit
  352.           bit of data which we read and relocated, this would be
  353.           0x000000ff. When we have relocs which have an addend, such as
  354.           sun4 extended relocs, the value in the offset part of a
  355.           relocating field is garbage so we never use it. In this case
  356.           the mask would be 0x00000000. */
  357.   bfd_word src_mask;
  358.  
  359.            /* The dst_mask is what parts of the instruction are replaced
  360.           into the instruction. In most cases src_mask == dst_mask,
  361.           except in the above special case, where dst_mask would be
  362.           0x000000ff, and src_mask would be 0x00000000.   */
  363.   bfd_word dst_mask;           
  364.  
  365.            /* When some formats create PC relative instructions, they leave
  366.           the value of the pc of the place being relocated in the offset
  367.           slot of the instruction, so that a PC relative relocation can
  368.           be made just by adding in an ordinary offset (eg sun3 a.out).
  369.           Some formats leave the displacement part of an instruction
  370.           empty (eg m88k bcs), this flag signals the fact.*/
  371.   boolean pcrel_offset;
  372.  
  373. } reloc_howto_type;
  374.  
  375. `the HOWTO macro'
  376. .................
  377.  
  378. *Description*
  379.  The HOWTO define is horrible and will go away.
  380.  
  381. #define HOWTO(C, R,S,B, P, BI, ABS, O, SF, NAME, INPLACE, MASKSRC, MASKDST, PC) \
  382.   {(unsigned)C,R,S,B, P, BI, ABS,O,SF,NAME,INPLACE,MASKSRC,MASKDST,PC}
  383.  
  384.  
  385. *Description*
  386.  And will be replaced with the totally magic way. But for the moment, we
  387. are compatible, so do it this way..
  388.  
  389. #define NEWHOWTO( FUNCTION, NAME,SIZE,REL,IN) HOWTO(0,0,SIZE,0,REL,0,false,false,FUNCTION, NAME,false,0,0,IN)
  390.  
  391.  
  392. *Description*
  393.  Helper routine to turn a symbol into a relocation value.
  394.  
  395. #define HOWTO_PREPARE(relocation, symbol)      \
  396.   {                                            \
  397.   if (symbol != (asymbol *)NULL) {             \
  398.     if (symbol->section == &bfd_com_section) { \
  399.       relocation = 0;                          \
  400.     }                                          \
  401.     else {                                     \
  402.       relocation = symbol->value;              \
  403.     }                                          \
  404.   }                                            \
  405. }
  406.  
  407.  
  408. `reloc_chain'
  409. ..............
  410.  
  411. *Description*
  412.  How relocs are tied together
  413.  
  414. typedef unsigned char bfd_byte;
  415.  
  416. typedef struct relent_chain {
  417.   arelent relent;
  418.   struct   relent_chain *next;
  419. } arelent_chain;
  420.  
  421.  
  422. `bfd_perform_relocation'
  423. .........................
  424.  
  425. *Synopsis*
  426.  
  427. bfd_reloc_status_type
  428. bfd_perform_relocation
  429.    (bfd * abfd,
  430.     arelent *reloc_entry,
  431.     PTR data,
  432.     asection *input_section,
  433.     bfd *output_bfd);
  434.  
  435. *Description*
  436.  If an output_bfd is supplied to this function the generated image will be
  437. relocatable, the relocations are copied to the output file after they
  438. have been changed to reflect the new state of the world. There are
  439. two ways of reflecting the results of partial linkage in an output
  440. file; by modifying the output data in place, and by modifying the
  441. relocation record.  Some native formats (eg basic a.out and basic
  442. coff) have no way of specifying an addend in the relocation type, so
  443. the addend has to go in the output data.  This is no big deal since
  444. in these formats the output data slot will always be big enough for
  445. the addend. Complex reloc types with addends were invented to solve
  446. just this problem.
  447.  
  448.  
  449. 
  450. File: bfd.info,  Node: howto manager,  Prev: typedef arelent,  Up: Relocations
  451.  
  452. The howto manager
  453. =================
  454.  
  455. When an application wants to create a relocation, but doesn't know what
  456. the target machine might call it, it can find out by using this bit
  457. of code.
  458.  
  459. `bfd_reloc_code_type'
  460. .....................
  461.  
  462. *Description*
  463.  The insides of a reloc code
  464.  
  465. .
  466.  
  467. typedef enum bfd_reloc_code_real 
  468. {
  469.            /* 16 bits wide, simple reloc */
  470.   BFD_RELOC_16,        
  471.  
  472.            /* 8 bits wide, but used to form an address like 0xffnn */
  473.   BFD_RELOC_8_FFnn,
  474.  
  475.            /* 8 bits wide, simple */
  476.   BFD_RELOC_8,
  477.  
  478.            /* 8 bits wide, pc relative */
  479.   BFD_RELOC_8_PCREL,
  480.  
  481.            /* The type of reloc used to build a contructor table - at the
  482.           moment probably a 32 bit wide abs address, but the cpu can
  483.           choose. */
  484.  
  485.   BFD_RELOC_CTOR
  486.  } bfd_reloc_code_real_type;
  487.  
  488. bfd_reloc_type_lookup
  489. =====================
  490.  
  491.  
  492. *Synopsis*
  493.  
  494. CONST struct reloc_howto_struct *
  495. bfd_reloc_type_lookup
  496.    (CONST bfd_arch_info_type *arch, bfd_reloc_code_type code);
  497.  
  498. *Description*
  499.  This routine returns a pointer to a howto struct which when invoked, will
  500. perform the supplied relocation on data from the architecture noted.
  501.  
  502. `bfd_default_reloc_type_lookup'
  503. ...............................
  504.  
  505. *Synopsis*
  506.  
  507. CONST struct reloc_howto_struct *bfd_default_reloc_type_lookup
  508.    (CONST struct bfd_arch_info *,
  509.     bfd_reloc_code_type  code);
  510.  
  511. *Description*
  512.  Provides a default relocation lookuperer for any architectue
  513.  
  514. `bfd_generic_relax_section'
  515. ...........................
  516.  
  517. *Synopsis*
  518.  
  519. boolean bfd_generic_relax_section
  520.    (bfd *abfd,
  521.     asection *section,
  522.     asymbol **symbols);
  523.  
  524. *Description*
  525.  Provides default handling for relaxing for back ends which don't do
  526. relaxing - ie does nothing
  527.  
  528. `bfd_generic_get_relocated_section_contents'
  529. ............................................
  530.  
  531. *Synopsis*
  532.  
  533. bfd_byte *
  534. bfd_generic_get_relocated_section_contents(bfd *abfd,
  535.     struct bfd_seclet_struct  *seclet)
  536.  
  537. *Description*
  538.  Provides default handling of relocation effort for back ends which can't
  539. be bothered to do it efficiently.
  540.  
  541.  
  542. 
  543. File: bfd.info,  Node: Core Files,  Next: Targets,  Prev: Relocations,  Up: BFD front end
  544.  
  545. Core files
  546. ==========
  547.  
  548.  
  549. *Description*
  550.  Buff output this facinating topic
  551.  
  552. `bfd_core_file_failing_command'
  553. ...............................
  554.  
  555. *Synopsis*
  556.  
  557. CONST char *bfd_core_file_failing_command(bfd *);
  558.  
  559. *Description*
  560.  Returns a read-only string explaining what program was running when it
  561. failed and produced the core file being read
  562.  
  563. `bfd_core_file_failing_signal'
  564. ..............................
  565.  
  566. *Synopsis*
  567.  
  568. int bfd_core_file_failing_signal(bfd *);
  569.  
  570. *Description*
  571.  Returns the signal number which caused the core dump which generated the
  572. file the BFD is attached to.
  573.  
  574. `core_file_matches_executable_p'
  575. ................................
  576.  
  577. *Synopsis*
  578.  
  579. boolean core_file_matches_executable_p
  580.    (bfd *core_bfd, bfd *exec_bfd);
  581.  
  582. *Description*
  583.  Returns `true' if the core file attached to CORE_BFD was generated by a
  584. run of the executable file attached to EXEC_BFD, or else `false'.
  585.  
  586.  
  587. 
  588. File: bfd.info,  Node: Targets,  Next: Architectures,  Prev: Core Files,  Up: BFD front end
  589.  
  590. Targets
  591. =======
  592.  
  593.  
  594. *Description*
  595.  Each port of BFD to a different machine requries the creation of a target
  596. back end. All the back end provides to the root part of BFD is a
  597. structure containing pointers to functions which perform certain low
  598. level operations on files. BFD translates the applications's requests
  599. through a pointer into calls to the back end routines.  When a file
  600. is opened with `bfd_openr', its format and target are unknown. BFD
  601. uses various mechanisms to determine how to interpret the file. The
  602. operations performed are:
  603.  
  604. * `new_bfd', then `bfd_find_target' is called with the target string
  605. supplied to `bfd_openr' and the new BFD pointer.
  606.  
  607. * it looks up the environment variable `GNUTARGET' and uses that as the
  608. target string.
  609.  
  610. * `default', then the first item in the target vector is used as the
  611. target type. *Note bfd_target::.
  612.  
  613. * one by one, until a match on target name is found. When found, that
  614. is used.
  615.  
  616. * `bfd_openr'.
  617.  
  618. * `bfd_open_file', and returns the BFD.  Once the BFD has been opened
  619. and the target selected, the file format may be determined. This is
  620. done by calling `bfd_check_format' on the BFD with a suggested
  621. format. The routine returns `true' when the application guesses right.
  622.  
  623. * Menu:
  624.  
  625. * bfd_target::
  626.  
  627.  
  628.  
  629. 
  630. File: bfd.info,  Node: bfd_target,  Prev: Targets,  Up: Targets
  631.  
  632. bfd_target
  633. ----------
  634.  
  635.  
  636. *Description*
  637.  This structure contains everything that BFD knows about a target. It
  638. includes things like its byte order, name, what routines to call to
  639. do various operations, etc.    Every BFD points to a target structure
  640. with its `xvec' member.  Shortcut for declaring fields which are
  641. prototyped function pointers, while avoiding anguish on compilers
  642. that don't support protos.
  643.  
  644. #define SDEF(ret, name, arglist) \
  645.                 PROTO(ret,(*name),arglist)
  646. #define SDEF_FMT(ret, name, arglist) \
  647.                 PROTO(ret,(*name[bfd_type_end]),arglist)
  648.  
  649. These macros are used to dispatch to functions through the bfd_target
  650. vector. They are used in a number of macros further down in `bfd.h',
  651. and are also used when calling various routines by hand inside the
  652. BFD implementation.  The "arglist" argument must be parenthesized; it
  653. contains all the arguments to the called function.
  654.  
  655. #define BFD_SEND(bfd, message, arglist) \
  656.                ((*((bfd)->xvec->message)) arglist)
  657.  
  658. For operations which index on the BFD format
  659.  
  660. #define BFD_SEND_FMT(bfd, message, arglist) \
  661.             (((bfd)->xvec->message[(int)((bfd)->format)]) arglist)
  662.  
  663. This is the struct which defines the type of BFD this is.  The `xvec'
  664. member of the struct `bfd' itself points here.  Each module that
  665. implements access to a different target under BFD, defines one of
  666. these.  FIXME, these names should be rationalised with the names of
  667. the entry points which call them. Too bad we can't have one macro to
  668. define them both!
  669.  
  670. typedef struct bfd_target
  671. {
  672.  
  673. identifies the kind of target, eg SunOS4, Ultrix, etc
  674.  
  675.   char *name;
  676.  
  677. The "flavour" of a back end is a general indication about the contents
  678. of a file.
  679.  
  680.   enum target_flavour {
  681.     bfd_target_unknown_flavour,
  682.     bfd_target_aout_flavour,
  683.     bfd_target_coff_flavour,
  684.     bfd_target_elf_flavour,
  685.     bfd_target_ieee_flavour,
  686.     bfd_target_oasys_flavour,
  687.     bfd_target_srec_flavour} flavour;
  688.  
  689. The order of bytes within the data area of a file.
  690.  
  691.   boolean byteorder_big_p;
  692.  
  693. The order of bytes within the header parts of a file.
  694.  
  695.   boolean header_byteorder_big_p;
  696.  
  697. This is a mask of all the flags which an executable may have set - from
  698. the set `NO_FLAGS', `HAS_RELOC', ...`D_PAGED'.
  699.  
  700.   flagword object_flags;
  701.  
  702. This is a mask of all the flags which a section may have set - from the
  703. set `SEC_NO_FLAGS', `SEC_ALLOC', ...`SET_NEVER_LOAD'.
  704.  
  705.   flagword section_flags;
  706.  
  707. The pad character for filenames within an archive header.
  708.  
  709.   char ar_pad_char;
  710.  
  711. The maximum number of characters in an archive header.
  712.  
  713.  unsigned short ar_max_namelen;
  714.  
  715. The minimum alignment restriction for any section.
  716.  
  717.   unsigned int align_power_min;
  718.  
  719. Entries for byte swapping for data. These are different to the other
  720. entry points, since they don't take BFD as first arg.  Certain other
  721. handlers could do the same.
  722.  
  723.   SDEF (bfd_vma,      bfd_getx64, (bfd_byte *));
  724.   SDEF (void,         bfd_putx64, (bfd_vma, bfd_byte *));
  725.   SDEF (bfd_vma, bfd_getx32, (bfd_byte *));
  726.   SDEF (void,         bfd_putx32, (bfd_vma, bfd_byte *));
  727.   SDEF (bfd_vma, bfd_getx16, (bfd_byte *));
  728.   SDEF (void,         bfd_putx16, (bfd_vma, bfd_byte *));
  729.  
  730. Byte swapping for the headers
  731.  
  732.   SDEF (bfd_vma,   bfd_h_getx64, (bfd_byte *));
  733.   SDEF (void,          bfd_h_putx64, (bfd_vma, bfd_byte *));
  734.   SDEF (bfd_vma,  bfd_h_getx32, (bfd_byte *));
  735.   SDEF (void,          bfd_h_putx32, (bfd_vma, bfd_byte *));
  736.   SDEF (bfd_vma,  bfd_h_getx16, (bfd_byte *));
  737.   SDEF (void,          bfd_h_putx16, (bfd_vma, bfd_byte *));
  738.  
  739. Format dependent routines, these turn into vectors of entry points
  740. within the target vector structure; one for each format to check. 
  741. Check the format of a file being read.  Return bfd_target * or zero.
  742.  
  743.   SDEF_FMT (struct bfd_target *, _bfd_check_format, (bfd *));
  744.  
  745. Set the format of a file being written.
  746.  
  747.   SDEF_FMT (boolean,            _bfd_set_format, (bfd *));
  748.  
  749. Write cached information into a file being written, at bfd_close.
  750.  
  751.   SDEF_FMT (boolean,            _bfd_write_contents, (bfd *));
  752.  
  753. The following functions are defined in `JUMP_TABLE'. The idea is that
  754. the back end writer of `foo' names all the routines
  755. `foo_'ENTRY_POINT, `JUMP_TABLE' will built the entries in this
  756. structure in the right order.  Core file entry points
  757.  
  758.   SDEF (char *, _core_file_failing_command, (bfd *));
  759.   SDEF (int,    _core_file_failing_signal, (bfd *));
  760.   SDEF (boolean, _core_file_matches_executable_p, (bfd *, bfd *));
  761.  
  762. Archive entry points
  763.  
  764.  SDEF (boolean, _bfd_slurp_armap, (bfd *));
  765.  SDEF (boolean, _bfd_slurp_extended_name_table, (bfd *));
  766.  SDEF (void,   _bfd_truncate_arname, (bfd *, CONST char *, char *));
  767.  SDEF (boolean, write_armap, (bfd *arch, 
  768.                               unsigned int elength,
  769.                               struct orl *map,
  770.                               unsigned int orl_count, 
  771.                               int stridx));
  772.  
  773. Standard stuff.
  774.  
  775.   SDEF (boolean, _close_and_cleanup, (bfd *));
  776.   SDEF (boolean, _bfd_set_section_contents, (bfd *, sec_ptr, PTR,
  777.                                             file_ptr, bfd_size_type));
  778.   SDEF (boolean, _bfd_get_section_contents, (bfd *, sec_ptr, PTR, 
  779.                                             file_ptr, bfd_size_type));
  780.   SDEF (boolean, _new_section_hook, (bfd *, sec_ptr));
  781.  
  782. Symbols and reloctions
  783.  
  784.   SDEF (unsigned int, _get_symtab_upper_bound, (bfd *));
  785.   SDEF (unsigned int, _bfd_canonicalize_symtab,
  786.            (bfd *, struct symbol_cache_entry **));
  787.   SDEF (unsigned int, _get_reloc_upper_bound, (bfd *, sec_ptr));
  788.   SDEF (unsigned int, _bfd_canonicalize_reloc, (bfd *, sec_ptr, arelent **,
  789.                                                struct symbol_cache_entry**));
  790.   SDEF (struct symbol_cache_entry  *, _bfd_make_empty_symbol, (bfd *));
  791.   SDEF (void,     _bfd_print_symbol, (bfd *, PTR, struct symbol_cache_entry  *,
  792.                                       bfd_print_symbol_type));
  793. #define bfd_print_symbol(b,p,s,e) BFD_SEND(b, _bfd_print_symbol, (b,p,s,e))
  794.   SDEF (alent *,   _get_lineno, (bfd *, struct symbol_cache_entry  *));
  795.  
  796.   SDEF (boolean,   _bfd_set_arch_mach, (bfd *, enum bfd_architecture,
  797.                                        unsigned long));
  798.  
  799.   SDEF (bfd *,  openr_next_archived_file, (bfd *arch, bfd *prev));
  800.   SDEF (boolean, _bfd_find_nearest_line,
  801.         (bfd *abfd, struct sec  *section,
  802.          struct symbol_cache_entry  **symbols,bfd_vma offset,
  803.         CONST char **file, CONST char **func, unsigned int *line));
  804.   SDEF (int,    _bfd_stat_arch_elt, (bfd *, struct stat *));
  805.  
  806.   SDEF (int,    _bfd_sizeof_headers, (bfd *, boolean));
  807.  
  808.   SDEF (void, _bfd_debug_info_start, (bfd *));
  809.   SDEF (void, _bfd_debug_info_end, (bfd *));
  810.   SDEF (void, _bfd_debug_info_accumulate, (bfd *, struct sec  *));
  811.   SDEF (bfd_byte *, _bfd_get_relocated_section_contents, (bfd*,struct bfd_seclet_struct *));
  812.   SDEF (boolean,_bfd_relax_section,(bfd *, struct sec *, struct symbol_cache_entry **));
  813.  
  814. Special entry points for gdb to swap in coff symbol table parts
  815.  
  816.   SDEF(void, _bfd_coff_swap_aux_in,(
  817.        bfd            *abfd ,
  818.        PTR             ext,
  819.        int             type,
  820.        int             class ,
  821.        PTR             in));
  822.  
  823.   SDEF(void, _bfd_coff_swap_sym_in,(
  824.        bfd            *abfd ,
  825.        PTR             ext,
  826.        PTR             in));
  827.  
  828.   SDEF(void, _bfd_coff_swap_lineno_in,  (
  829.        bfd            *abfd,
  830.        PTR            ext,
  831.        PTR             in));
  832.  
  833. Special entry points for gas to swap coff parts
  834.  
  835.  SDEF(unsigned int, _bfd_coff_swap_aux_out,(
  836.        bfd       *abfd,
  837.        PTR    in,
  838.        int        type,
  839.        int        class,
  840.        PTR        ext));
  841.  
  842.  SDEF(unsigned int, _bfd_coff_swap_sym_out,(
  843.       bfd      *abfd,
  844.       PTR    in,
  845.       PTR    ext));
  846.  
  847.  SDEF(unsigned int, _bfd_coff_swap_lineno_out,(
  848.           bfd       *abfd,
  849.           PTR    in,
  850.     PTR    ext));
  851.  
  852.  SDEF(unsigned int, _bfd_coff_swap_reloc_out,(
  853.           bfd     *abfd,
  854.          PTR    src,
  855.     PTR    dst));
  856.  
  857.  SDEF(unsigned int, _bfd_coff_swap_filehdr_out,(
  858.           bfd      *abfd,
  859.     PTR     in,
  860.     PTR     out));
  861.  
  862.  SDEF(unsigned int, _bfd_coff_swap_aouthdr_out,(
  863.           bfd     *abfd,
  864.     PTR     in,
  865.     PTR    out));
  866.  
  867.  SDEF(unsigned int, _bfd_coff_swap_scnhdr_out,(
  868.           bfd      *abfd,
  869.           PTR    in,
  870.     PTR    out));
  871.  
  872. } bfd_target;
  873.  
  874.  
  875. `bfd_find_target'
  876. ..................
  877.  
  878. *Description*
  879.  Returns a pointer to the transfer vector for the object target named
  880. target_name.  If target_name is NULL, chooses the one in the
  881. environment variable GNUTARGET; if that is null or not defined
  882. thenthe first entry in the target list is chosen.  Passing in the
  883. string "default" or setting the environment variable to "default"
  884. will cause the first entry in the target list to be returned, and
  885. "target_defaulted" will be set in the BFD.  This causes
  886. `bfd_check_format' to loop over all the targets to find the one that
  887. matches the file being read.
  888.  
  889. *Synopsis*
  890.  
  891. bfd_target *bfd_find_target(CONST char *, bfd *);
  892.  
  893. `bfd_target_list'
  894. .................
  895.  
  896. *Description*
  897.  This function returns a freshly malloced NULL-terminated vector of the
  898. names of all the valid BFD targets. Do not modify the names
  899.  
  900. *Synopsis*
  901.  
  902. CONST char **bfd_target_list(void);
  903.  
  904.  
  905. 
  906. File: bfd.info,  Node: Architectures,  Next: Opening and Closing,  Prev: Targets,  Up: BFD front end
  907.  
  908. Architectures
  909. =============
  910.  
  911. BFD's idea of an architecture is implimented in `archures.c'. BFD keeps
  912. one atom in a BFD describing the architecture of the data attached to
  913. the BFD;  a pointer to a `bfd_arch_info_type'.   Pointers to
  914. structures can be requested independently of a bfd so that an
  915. architecture's information can be interrogated without access to an
  916. open bfd.  The arch information is provided by each architecture
  917. package.  The set of default architectures is selected by the #define
  918. `SELECT_ARCHITECTURES'.  This is normally set up in the `config\/h\-'
  919. file of your choice.  If the name is not defined, then all the
  920. architectures supported are included.  When BFD starts up, all the
  921. architectures are called with an initialize method.  It is up to the
  922. architecture back end to insert as many items into the list of arches
  923. as it wants to, generally this would be one for each machine and one
  924. for the default case (an item with a machine field of 0).
  925.  
  926. bfd_architecture
  927. ----------------
  928.  
  929.  
  930. *Description*
  931.  This enum gives the object file's CPU architecture, in a global sense.
  932. E.g. what processor family does it belong to?  There is another
  933. field, which indicates what processor within the family is in use. 
  934. The machine gives a number which distingushes different versions of
  935. the architecture, containing for example 2 and 3 for Intel i960 KA
  936. and i960 KB, and 68020 and 68030 for Motorola 68020 and 68030.
  937.  
  938. enum bfd_architecture 
  939. {
  940.   bfd_arch_unknown,    /* File arch not known */
  941.   bfd_arch_obscure,    /* Arch known, not one of these */
  942.   bfd_arch_m68k,       /* Motorola 68xxx */
  943.   bfd_arch_vax,        /* DEC Vax */   
  944.   bfd_arch_i960,       /* Intel 960 */
  945.      /* The order of the following is important.
  946.        lower number indicates a machine type that 
  947.        only accepts a subset of the instructions
  948.        available to machines with higher numbers.
  949.        The exception is the "ca", which is
  950.        incompatible with all other machines except 
  951.        "core". */
  952.  
  953. #define bfd_mach_i960_core      1
  954. #define bfd_mach_i960_ka_sa     2
  955. #define bfd_mach_i960_kb_sb     3
  956. #define bfd_mach_i960_mc        4
  957. #define bfd_mach_i960_xa        5
  958. #define bfd_mach_i960_ca        6
  959.  
  960.   bfd_arch_a29k,       /* AMD 29000 */
  961.   bfd_arch_sparc,      /* SPARC */
  962.   bfd_arch_mips,       /* MIPS Rxxxx */
  963.   bfd_arch_i386,       /* Intel 386 */
  964.   bfd_arch_ns32k,      /* National Semiconductor 32xxx */
  965.   bfd_arch_tahoe,      /* CCI/Harris Tahoe */
  966.   bfd_arch_i860,       /* Intel 860 */
  967.   bfd_arch_romp,       /* IBM ROMP PC/RT */
  968.   bfd_arch_alliant,    /* Alliant */
  969.   bfd_arch_convex,     /* Convex */
  970.   bfd_arch_m88k,       /* Motorola 88xxx */
  971.   bfd_arch_pyramid,    /* Pyramid Technology */
  972.   bfd_arch_h8300,      /* Hitachi H8/300 */
  973.   bfd_arch_rs6000,     /* IBM RS/6000 */
  974.   bfd_arch_last
  975.   };
  976.  
  977.  
  978. bfd_arch_info
  979. --------------
  980.  
  981.  
  982. *Description*
  983.  This structure contains information on architectures for use within BFD.
  984.  
  985. typedef int bfd_reloc_code_type;
  986.  
  987. typedef struct bfd_arch_info 
  988. {
  989.   int bits_per_word;
  990.   int bits_per_address;
  991.   int bits_per_byte;
  992.   enum bfd_architecture arch;
  993.   long mach;
  994.   char *arch_name;
  995.   CONST  char *printable_name;
  996.   /* true if this is the default machine for the architecture */
  997.  unsigned int section_align_power;
  998.   boolean the_default;    
  999.   CONST struct bfd_arch_info * EXFUN((*compatible),
  1000.     (CONST struct bfd_arch_info *a,
  1001.      CONST struct bfd_arch_info *b));
  1002.  
  1003.   boolean EXFUN((*scan),(CONST struct bfd_arch_info *,CONST char *));
  1004.   unsigned int EXFUN((*disassemble),(bfd_vma addr, CONST char *data,
  1005.                      PTR stream));
  1006.   CONST struct reloc_howto_struct *EXFUN((*reloc_type_lookup),
  1007.     (CONST struct bfd_arch_info *,
  1008.     bfd_reloc_code_type  code));
  1009.  
  1010.   struct bfd_arch_info *next;
  1011.  
  1012. } bfd_arch_info_type;
  1013.  
  1014.  
  1015. `bfd_printable_name'
  1016. .....................
  1017.  
  1018. *Synopsis*
  1019.  
  1020. CONST char *bfd_printable_name(bfd *abfd);
  1021.  
  1022. *Description*
  1023.  Return a printable string representing the architecture and machine from
  1024. the pointer to the arch info structure
  1025.  
  1026. `bfd_scan_arch'
  1027. ...............
  1028.  
  1029. *Synopsis*
  1030.  
  1031. bfd_arch_info_type *bfd_scan_arch(CONST char *);
  1032.  
  1033. *Description*
  1034.  This routine is provided with a string and tries to work out if bfd
  1035. supports any cpu which could be described with the name provided. 
  1036. The routine returns a pointer to an arch_info structure if a machine
  1037. is found, otherwise NULL.
  1038.  
  1039. `bfd_arch_get_compatible'
  1040. .........................
  1041.  
  1042. *Synopsis*
  1043.  
  1044. CONST bfd_arch_info_type *bfd_arch_get_compatible(
  1045.     CONST bfd *abfd,
  1046.     CONST bfd *bbfd);
  1047.  
  1048. *Description*
  1049.  This routine is used to determine whether two BFDs' architectures and
  1050. achine types are compatible.  It calculates the lowest common
  1051. denominator between the two architectures and machine types implied
  1052. by the BFDs and returns a pointer to an arch_info structure
  1053. describing the compatible machine.
  1054.  
  1055. `bfd_default_arch_struct'
  1056. .........................
  1057.  
  1058. *Description*
  1059.  The `bfd_default_arch_struct' is an item of `bfd_arch_info_type' which
  1060. has been initialized to a fairly generic state.  A BFD starts life by
  1061. pointing to this structure, until the correct back end has determined
  1062. the real architecture of the file.
  1063.  
  1064. extern bfd_arch_info_type bfd_default_arch_struct;
  1065.  
  1066.  
  1067. `bfd_set_arch_info'
  1068. ....................
  1069.  
  1070. *Synopsis*
  1071.  
  1072. void bfd_set_arch_info(bfd *, bfd_arch_info_type *);
  1073.  
  1074. `bfd_default_set_arch_mach'
  1075. ...........................
  1076.  
  1077. *Synopsis*
  1078.  
  1079. boolean bfd_default_set_arch_mach(bfd *abfd,
  1080.     enum bfd_architecture arch,
  1081.     unsigned long mach);
  1082.  
  1083. *Description*
  1084.  Set the architecture and machine type in a bfd. This finds the correct
  1085. pointer to structure and inserts it into the arch_info pointer.
  1086.  
  1087. `bfd_get_arch'
  1088. ..............
  1089.  
  1090. *Synopsis*
  1091.  
  1092. enum bfd_architecture bfd_get_arch(bfd *abfd);
  1093.  
  1094. *Description*
  1095.  Returns the enumerated type which describes the supplied bfd's architecture
  1096.  
  1097. `bfd_get_mach'
  1098. ..............
  1099.  
  1100. *Synopsis*
  1101.  
  1102. unsigned long bfd_get_mach(bfd *abfd);
  1103.  
  1104. *Description*
  1105.  Returns the long type which describes the supplied bfd's machine
  1106.  
  1107. `bfd_arch_bits_per_byte'
  1108. ........................
  1109.  
  1110. *Synopsis*
  1111.  
  1112. unsigned int bfd_arch_bits_per_byte(bfd *abfd);
  1113.  
  1114. *Description*
  1115.  Returns the number of bits in one of the architectures bytes
  1116.  
  1117. `bfd_arch_bits_per_address'
  1118. ...........................
  1119.  
  1120. *Synopsis*
  1121.  
  1122. unsigned int bfd_arch_bits_per_address(bfd *abfd);
  1123.  
  1124. *Description*
  1125.  Returns the number of bits in one of the architectures addresses
  1126.  
  1127. `bfd_arch_init'
  1128. ...............
  1129.  
  1130. *Synopsis*
  1131.  
  1132. void  bfd_arch_init(void);
  1133.  
  1134. *Description*
  1135.  This routine initializes the architecture dispatch table by calling all
  1136. installed architecture packages and getting them to poke around.
  1137.  
  1138. `bfd_arch_linkin'
  1139. .................
  1140.  
  1141. *Synopsis*
  1142.  
  1143. void bfd_arch_linkin(bfd_arch_info_type *);
  1144.  
  1145. *Description*
  1146.  Link the provided arch info structure into the list
  1147.  
  1148. `bfd_default_compatible'
  1149. ........................
  1150.  
  1151. *Synopsis*
  1152.  
  1153. CONST bfd_arch_info_type *bfd_default_compatible
  1154.    (CONST bfd_arch_info_type *a,
  1155.     CONST bfd_arch_info_type *b);
  1156.  
  1157. *Description*
  1158.  The default function for testing for compatibility.
  1159.  
  1160. `bfd_default_scan'
  1161. ..................
  1162.  
  1163. *Synopsis*
  1164.  
  1165. boolean bfd_default_scan(CONST struct bfd_arch_info *, CONST char *);
  1166.  
  1167. *Description*
  1168.  The default function for working out whether this is an architecture hit
  1169. and a machine hit.
  1170.  
  1171. `bfd_get_arch_info'
  1172. ...................
  1173.  
  1174. *Synopsis*
  1175.  
  1176. bfd_arch_info_type * bfd_get_arch_info(bfd *);
  1177.  
  1178. `bfd_lookup_arch'
  1179. .................
  1180.  
  1181. *Synopsis*
  1182.  
  1183. bfd_arch_info_type *bfd_lookup_arch
  1184.    (enum bfd_architecture
  1185.     arch,
  1186.     long machine);
  1187.  
  1188. *Description*
  1189.  Look for the architecure info struct which matches the arguments given. A
  1190. machine of 0 will match the machine/architecture structure which
  1191. marks itself as the default.
  1192.  
  1193. `bfd_printable_arch_mach'
  1194. .........................
  1195.  
  1196. *Synopsis*
  1197.  
  1198. CONST char * bfd_printable_arch_mach
  1199.    (enum bfd_architecture arch, unsigned long machine);
  1200.  
  1201. *Description*
  1202.  Return a printable string representing the architecture and machine type.
  1203. NB. The use of this routine is depreciated.
  1204.  
  1205.  
  1206. 
  1207. File: bfd.info,  Node: Opening and Closing,  Next: Constructors,  Prev: Architectures,  Up: BFD front end
  1208.  
  1209. Opening and Closing BFDs
  1210. ========================
  1211.  
  1212.  
  1213. `bfd_openr'
  1214. ............
  1215.  
  1216. *Synopsis*
  1217.  
  1218. bfd *bfd_openr(CONST char *filename, CONST char*target);
  1219.  
  1220. *Description*
  1221.  This function opens the file supplied (using `fopen') with the target
  1222. supplied, it returns a pointer to the created BFD.  If NULL is
  1223. returned then an error has occured. Possible errors are `no_memory',
  1224. `invalid_target' or `system_call' error.
  1225.  
  1226. `bfd_fdopenr'
  1227. .............
  1228.  
  1229. *Synopsis*
  1230.  
  1231. bfd *bfd_fdopenr(CONST char *filename, CONST char *target, int fd);
  1232.  
  1233. *Description*
  1234.  bfd_fdopenr is to bfd_fopenr much like  fdopen is to fopen.  It opens a
  1235. BFD on a file already described by the FD supplied.  Possible errors
  1236. are no_memory, invalid_target and system_call error.
  1237.  
  1238. `bfd_openw'
  1239. ...........
  1240.  
  1241. *Synopsis*
  1242.  
  1243. bfd *bfd_openw(CONST char *filename, CONST char *target);
  1244.  
  1245. *Description*
  1246.  Creates a BFD, associated with file FILENAME, using the file format
  1247. TARGET, and returns a pointer to it.  Possible errors are
  1248. system_call_error, no_memory, invalid_target.
  1249.  
  1250. `bfd_close'
  1251. ...........
  1252.  
  1253. *Synopsis*
  1254.  
  1255. boolean bfd_close(bfd *);
  1256.  
  1257. *Description*
  1258.  This function closes a BFD. If the BFD was open for writing, then pending
  1259. operations are completed and the file written out and closed. If the
  1260. created file is executable, then `chmod' is called to mark it as such.
  1261. All memory attached to the BFD's obstacks is released.
  1262.  
  1263. *Returns*
  1264.  `true' is returned if all is ok, otherwise `false'.
  1265.  
  1266. `bfd_close_all_done'
  1267. ....................
  1268.  
  1269. *Synopsis*
  1270.  
  1271. boolean bfd_close_all_done(bfd *);
  1272.  
  1273. *Description*
  1274.  This function closes a BFD. It differs from `bfd_close' since it does not
  1275. complete any pending operations.  This routine would be used if the
  1276. application had just used BFD for swapping and didn't want to use any
  1277. of the writing code.  If the created file is executable, then `chmod'
  1278. is called to mark it as such.  All memory attached to the BFD's
  1279. obstacks is released.
  1280.  
  1281. *Returns*
  1282.  `true' is returned if all is ok, otherwise `false'.
  1283.  
  1284. *Synopsis*
  1285.  
  1286. bfd_size_type bfd_alloc_size(bfd *abfd);
  1287.  
  1288. *Description*
  1289.  Return the number of bytes in the obstacks connected to the supplied BFD.
  1290.  
  1291. `bfd_create'
  1292. ............
  1293.  
  1294. *Synopsis*
  1295.  
  1296. bfd *bfd_create(CONST char *filename, bfd *template);
  1297.  
  1298. *Description*
  1299.  This routine creates a new BFD in the manner of `bfd_openw', but without
  1300. opening a file. The new BFD takes the target from the target used by
  1301. TEMPLATE. The format is always set to `bfd_object'.
  1302.  
  1303. `bfd_alloc_by_size_t'
  1304. .....................
  1305.  
  1306. *Synopsis*
  1307.  
  1308. PTR bfd_alloc_by_size_t(bfd *abfd, size_t wanted);
  1309.  
  1310. *Description*
  1311.  This function allocates a block of memory in the obstack attatched to
  1312. `abfd' and returns a pointer to it.
  1313.  
  1314.  
  1315. 
  1316. File: bfd.info,  Node: Constructors,  Next: Internal,  Prev: Opening and Closing,  Up: BFD front end
  1317.  
  1318. Constructors
  1319. ============
  1320.  
  1321. Classes in C++ have 'constructors' and 'destructors'.  These are
  1322. functions which are called automatically by the language whenever
  1323. data of a class is created or destroyed.  Class data which is static
  1324. data may also be have a type which requires 'construction', the
  1325. contructor must be called before the data can be referenced, so the
  1326. contructor must be called before the program begins.  The common
  1327. solution to this problem is for the compiler to call a magic function
  1328. as the first statement `main'.  This magic function, (often called
  1329. `__main') runs around calling the constructors for all the things
  1330. needing it.  With COFF the compile has a bargain with the linker et al.
  1331. All constructors are given strange names, for example
  1332. `__GLOBAL__$I$foo' might be the label of a contructor for the class
  1333. FOO.  The solution on unfortunate systems (most system V machines) is
  1334. to perform a partial link on all the .o files, do an `nm' on the
  1335. result, run `awk' or some such over the result looking for strange
  1336. `__GLOBAL__$' symbols, generate a C program from this, compile it and
  1337. link with the partially linked input. This process is usually called
  1338. `collect'.  Some versions of `a.out' use something called the
  1339. `set_vector' mechanism.  The constructor symbols are output from the
  1340. compiler with a special stab code saying that they are constructors,
  1341. and the linker can deal with them directly.  BFD allows applications
  1342. (ie the linker) to deal with constructor information independently of
  1343. their external implimentation by providing a set of entry points for
  1344. the indiviual object back ends to call which maintains a database of
  1345. the contructor information.  The application can interrogate the
  1346. database to find out what it wants.  The construction data essential
  1347. for the linker to be able to perform its job are:
  1348.  
  1349. * The asymbol of the contructor entry point contains all the
  1350. information necessary to call the function.
  1351.  
  1352. * The type of symbol, ie is it a contructor, a destructor or something
  1353. else someone dreamed up to make our lives difficult.  This module
  1354. takes this information and then builds extra sections attached to the
  1355. bfds which own the entry points.  It creates these sections as if
  1356. they were tables of pointers to the entry points, and builds
  1357. relocation entries to go with them so that the tables can be
  1358. relocated along with the data they reference.  These sections are
  1359. marked with a special bit (`SEC_CONSTRUCTOR') which the linker
  1360. notices and do with what it wants.
  1361.  
  1362.  
  1363. `bfd_constructor_entry '
  1364. .........................
  1365.  
  1366. *Synopsis*
  1367.  
  1368. void bfd_constructor_entry(bfd *abfd, 
  1369.     asymbol **symbol_ptr_ptr,
  1370.     CONST char*type);
  1371.  
  1372. *Description*
  1373.  This function is called with an a symbol describing the function to be
  1374. called, an string which descibes the xtor type, eg something like
  1375. "CTOR" or "DTOR" would be fine. And the bfd which owns the function.
  1376. Its duty is to create a section called "CTOR" or "DTOR" or whatever
  1377. if the bfd doesn't already have one, and grow a relocation table for
  1378. the entry points as they accumulate.
  1379.  
  1380.  
  1381. 
  1382. File: bfd.info,  Node: Internal,  Next: File Caching,  Prev: Constructors,  Up: BFD front end
  1383.  
  1384. libbfd
  1385. ======
  1386.  
  1387.  
  1388. *Description*
  1389.  This file contains various routines which are used within BFD.  They are
  1390. not intended for export, but are documented here for completeness.
  1391.  
  1392. `bfd_xmalloc'
  1393. .............
  1394.  
  1395. *Synopsis*
  1396.  
  1397. PTR  bfd_xmalloc( bfd_size_type size);
  1398.  
  1399. *Description*
  1400.  Like malloc, but exit if no more memory.
  1401.  
  1402. `bfd_write_bigendian_4byte_int'
  1403. ...............................
  1404.  
  1405. *Synopsis*
  1406.  
  1407. void bfd_write_bigendian_4byte_int(bfd *abfd,  int i);
  1408.  
  1409. *Description*
  1410.  Writes a 4 byte integer to the outputing bfd, in big endian mode
  1411. regardless of what else is going on.  This is usefull in archives.
  1412.  
  1413. `bfd_put_size'
  1414. ..............
  1415.  
  1416. `bfd_get_size'
  1417. ..............
  1418.  
  1419. *Description*
  1420.  These macros as used for reading and writing raw data in sections; each
  1421. access (except for bytes) is vectored through the target format of
  1422. the BFD and mangled accordingly. The mangling performs any necessary
  1423. endian translations and removes alignment restrictions.
  1424.  
  1425. #define bfd_put_8(abfd, val, ptr) \
  1426.                 (*((char *)ptr) = (char)val)
  1427. #define bfd_get_8(abfd, ptr) \
  1428.                 (*((char *)ptr))
  1429. #define bfd_put_16(abfd, val, ptr) \
  1430.                 BFD_SEND(abfd, bfd_putx16, (val,ptr))
  1431. #define bfd_get_16(abfd, ptr) \
  1432.                 BFD_SEND(abfd, bfd_getx16, (ptr))
  1433. #define bfd_put_32(abfd, val, ptr) \
  1434.                 BFD_SEND(abfd, bfd_putx32, (val,ptr))
  1435. #define bfd_get_32(abfd, ptr) \
  1436.                 BFD_SEND(abfd, bfd_getx32, (ptr))
  1437. #define bfd_put_64(abfd, val, ptr) \
  1438.                 BFD_SEND(abfd, bfd_putx64, (val, ptr))
  1439. #define bfd_get_64(abfd, ptr) \
  1440.                 BFD_SEND(abfd, bfd_getx64, (ptr))
  1441.  
  1442.  
  1443. `bfd_h_put_size'
  1444. .................
  1445.  
  1446. `bfd_h_get_size'
  1447. ................
  1448.  
  1449. *Description*
  1450.  These macros have the same function as their `bfd_get_x' bretherin,
  1451. except that they are used for removing information for the header
  1452. records of object files. Believe it or not, some object files keep
  1453. their header records in big endian order, and their data in little
  1454. endan order.
  1455.  
  1456. #define bfd_h_put_8(abfd, val, ptr) \
  1457.                 (*((char *)ptr) = (char)val)
  1458. #define bfd_h_get_8(abfd, ptr) \
  1459.                 (*((char *)ptr))
  1460. #define bfd_h_put_16(abfd, val, ptr) \
  1461.                 BFD_SEND(abfd, bfd_h_putx16,(val,ptr))
  1462. #define bfd_h_get_16(abfd, ptr) \
  1463.                 BFD_SEND(abfd, bfd_h_getx16,(ptr))
  1464. #define bfd_h_put_32(abfd, val, ptr) \
  1465.                 BFD_SEND(abfd, bfd_h_putx32,(val,ptr))
  1466. #define bfd_h_get_32(abfd, ptr) \
  1467.                 BFD_SEND(abfd, bfd_h_getx32,(ptr))
  1468. #define bfd_h_put_64(abfd, val, ptr) \
  1469.                 BFD_SEND(abfd, bfd_h_putx64,(val, ptr))
  1470. #define bfd_h_get_64(abfd, ptr) \
  1471.                 BFD_SEND(abfd, bfd_h_getx64,(ptr))
  1472.  
  1473.  
  1474. `bfd_log2'
  1475. ...........
  1476.  
  1477. *Description*
  1478.  Return the log base 2 of the value supplied, rounded up. eg an arg of
  1479. 1025 would return 11.
  1480.  
  1481. *Synopsis*
  1482.  
  1483. bfd_vma bfd_log2(bfd_vma x);
  1484.  
  1485.  
  1486. 
  1487. File: bfd.info,  Node: File Caching,  Prev: Internal,  Up: BFD front end
  1488.  
  1489. File Caching
  1490. ============
  1491.  
  1492. The file caching mechanism is embedded within BFD and allows the
  1493. application to open as many BFDs as it wants without regard to the
  1494. underlying operating system's file descriptor limit (often as low as
  1495. 20 open files).  The module in `cache.c' maintains a least recently
  1496. used list of `BFD_CACHE_MAX_OPEN' files, and exports the name
  1497. `bfd_cache_lookup' which runs around and makes sure that the required
  1498. BFD is open. If not, then it chooses a file to close, closes it and
  1499. opens the one wanted, returning its file handle.
  1500.  
  1501. `BFD_CACHE_MAX_OPEN macro'
  1502. ..........................
  1503.  
  1504. *Description*
  1505.  The maxiumum number of files which the cache will keep open at one time.
  1506.  
  1507. #define BFD_CACHE_MAX_OPEN 10
  1508.  
  1509.  
  1510. `bfd_last_cache'
  1511. .................
  1512.  
  1513. *Synopsis*
  1514.  
  1515. extern bfd *bfd_last_cache;
  1516.  
  1517. *Description*
  1518.  Zero, or a pointer to the topmost BFD on the chain.  This is used by the
  1519. `bfd_cache_lookup' macro in `libbfd.h' to determine when it can avoid
  1520. a function call.
  1521.  
  1522. `bfd_cache_lookup'
  1523. ..................
  1524.  
  1525. *Description*
  1526.  Checks to see if the required BFD is the same as the last one looked up.
  1527. If so then it can use the iostream in the BFD with impunity, since it
  1528. can't have changed since the last lookup, otherwise it has to perform
  1529. the complicated lookup function
  1530.  
  1531. #define bfd_cache_lookup(x) \
  1532.     ((x)==bfd_last_cache? \
  1533.       (FILE*)(bfd_last_cache->iostream): \
  1534.        bfd_cache_lookup_worker(x))
  1535.  
  1536.  
  1537. `bfd_cache_init'
  1538. .................
  1539.  
  1540. *Synopsis*
  1541.  
  1542. void  bfd_cache_init (bfd *);
  1543.  
  1544. *Description*
  1545.  Initialize a BFD by putting it on the cache LRU.
  1546.  
  1547. `bfd_cache_close'
  1548. .................
  1549.  
  1550. *Description*
  1551.  Remove the BFD from the cache. If the attached file is open, then close
  1552. it too.
  1553.  
  1554. *Synopsis*
  1555.  
  1556. void bfd_cache_close (bfd *);
  1557.  
  1558. `bfd_open_file'
  1559. ...............
  1560.  
  1561. *Description*
  1562.  Call the OS to open a file for this BFD.  Returns the FILE * (possibly
  1563. null) that results from this operation.  Sets up the BFD so that
  1564. future accesses know the file is open. If the FILE returned is null,
  1565. then there is won't have been put in the cache, so it won't have to
  1566. be removed from it.
  1567.  
  1568. *Synopsis*
  1569.  
  1570. FILE* bfd_open_file(bfd *);
  1571.  
  1572. `bfd_cache_lookup_worker'
  1573. .........................
  1574.  
  1575. *Description*
  1576.  Called when the macro `bfd_cache_lookup' fails to find a quick answer.
  1577. Finds a file descriptor for this BFD.  If necessary, it open it. If
  1578. there are already more than BFD_CACHE_MAX_OPEN files open, it trys to
  1579. close one first, to avoid running out of file descriptors.
  1580.  
  1581. *Synopsis*
  1582.  
  1583. FILE *bfd_cache_lookup_worker(bfd *);
  1584.  
  1585.  
  1586. 
  1587. File: bfd.info,  Node: BFD back end,  Next: Index,  Prev: BFD front end,  Up: Top
  1588.  
  1589. BFD back end
  1590. ************
  1591.  
  1592. * Menu:
  1593.  
  1594. * What to put where::
  1595. * aout ::    a.out backends
  1596. * coff ::    coff backends
  1597.  
  1598.  
  1599. 
  1600. File: bfd.info,  Node: What to Put Where,  Next: aout,  Prev: BFD back end,  Up: BFD back end
  1601.  
  1602. All of BFD lives in one directory.
  1603.  
  1604.  
  1605.